package com.second.app.thread.fair_nofair_test;

/**
 * @author gyz
 * @date 2021/2/2 15:05
 */
public class Main {
    public static void main(String[] args) {
        LockTestMethod lockTestMethod = new LockTestMethod();
        try {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    lockTestMethod.waitMethod();
                }
            };
            Thread threadA = new Thread(runnable);
            threadA.start();
            Thread.sleep(500);
            Thread threadB = new Thread(runnable);
            threadB.start();
            Thread.sleep(5000);
            //A线程是否在队列中排队
            System.out.println(lockTestMethod.lock.hasQueuedThread(threadA));
            //B线程是否在队列中排队
            System.out.println(lockTestMethod.lock.hasQueuedThread(threadB));
            //当前队列中的排队线程数
            System.out.println(lockTestMethod.lock.hasQueuedThreads());
            //当前持有锁的线程数
            System.out.println(lockTestMethod.lock.getHoldCount());

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }


}
